﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using BCCommon;
using BCDto.Trading.SaleGoods.SaleGoods;
using BCDto.Trading.SaleGoods.SaleGoodsCategory;
using BCDto.Trading.SaleGoods.SaleGoodsNorm;
using BCService.Trading.SaleGoods.SaleGoods;
using BCService.Trading.SaleGoods.SaleGoodsCategory;
using BCService.Trading.SaleShoppingCart;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace BCTMSRESTful.Controllers.Anonymous
{
    [Route("api/v1/[controller]")]
    [ApiController]
    public class TradingController : BCTMSRESTfulAPIController
    {
        private readonly ISaleGoodsCategoryService saleGoodsCategoryService;
        private readonly ISaleGoodsService saleGoodsService;
        

        public TradingController(ISaleGoodsCategoryService saleGoodsCategoryService, ISaleGoodsService saleGoodsService)
        {
            this.saleGoodsCategoryService = saleGoodsCategoryService;
            this.saleGoodsService = saleGoodsService;
        }
        #region 获取销售商品分类列表
        /// <summary>
        ///  获取销售商品分类列表
        /// </summary>
        /// <response code="200">获取销售商品分类列表</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(IEnumerable<SaleGoodsCategoryDto>), 200)]
        public IActionResult GoodsCategory()
        {
            return StatusCode((int)HttpStatusCode.OK, this.saleGoodsCategoryService.GetList());
        }
        #endregion

        #region 获取销售商品（分页）
        /// <summary>
        ///  获取销售商品（分页）
        /// </summary>
        /// <param name="saleGoodsCategoryId">商品分类Id</param>
        /// <param name="index">当前页码</param>
        /// <param name="size">当前页大小</param>
        /// <response code="200">获取销售商品（分页）</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpGet("[action]/{sale_goods_category_id}")]
        [ProducesResponseType(typeof(PageableList<SaleGoodsViewDto>), 200)]
        public IActionResult SaleGoods([FromRoute(Name = "sale_goods_category_id")]long saleGoodsCategoryId,
            [FromQuery(Name = "index")]int index = 1,
            [FromQuery(Name = "size")]int size = 10)
        {
            return StatusCode((int)HttpStatusCode.OK, this.saleGoodsService.GetMakeStaticPageListForSaleGoodsQuery(saleGoodsCategoryId, index, size));
        }
        #endregion

        #region 获取销售商品
        /// <summary>
        ///  获取销售商品
        /// </summary>
        /// <param name="saleGoodsId">销售商品Id</param>
        /// <response code="200">获取销售商品</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpGet("{sale_goods_id}")]
        [ProducesResponseType(typeof(SaleGoodsDto), 200)]
        public IActionResult Get([FromRoute(Name = "sale_goods_id")]long saleGoodsId)
        {
            return StatusCode((int)HttpStatusCode.OK, this.saleGoodsService.Get(saleGoodsId));
        }
        #endregion

        #region 获取销售商品规格列表
        /// <summary>
        ///  获取销售商品规格列表
        /// </summary>
        /// <param name="saleGoodsId">商品Id</param>
        /// <response code="200">获取销售商品规格列表</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpGet("GoodsNorms/{sale_goods_id}")]
        [ProducesResponseType(typeof(IEnumerable<SaleGoodsNormDto>), 200)]
        public IActionResult GetGoodsNormList([FromRoute(Name = "sale_goods_id")]long saleGoodsId)
        {
            return StatusCode((int)HttpStatusCode.OK, this.saleGoodsService.GetGoodsNormList(saleGoodsId));
        }
        #endregion
    }
}
